var request = require('superagent')
var loggerOG = require('../logger/outgoing')

var requestTimeout = (process.env.NODE_ENV === 'development') ? 30000 : 30000
var ajax = {
  post: function (url, datas, req) {
    return request.post(url).use(loggerOG({timestamp: true, outgoing: true, traceId: req.id || ''})).timeout(requestTimeout).send(datas)
  },
  get: function (url, datas, req) {
    return request.get(url).use(loggerOG({timestamp: true, outgoing: true, traceId: req.id || ''})).timeout(requestTimeout).query(datas)
  }
}

module.exports = ajax
